//
//  DealerCardTable.m
//  blackjack
//
//  Created by Thi Nguyen Tran on 3/24/10.
//  Copyright 2010 Epsilon. All rights reserved.
//

#import "DealerCardTable.h"

#define START_POS_X		27
#define START_POS_Y		22
#define BTN_WIDTH		85
#define BTN_HEIGHT		90

@implementation DealerCardTable

@synthesize delegate;

- (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        UIImage *img = [UIImage imageNamed:@"basic_dealer_num.png"];
		[self setImage:img];
    }
    return self;
}

- (void)touchesBegan:(NSSet *)touches 
		   withEvent:(UIEvent *)event {
	[self setUserInteractionEnabled:NO];
	UITouch * touch = [touches anyObject];
	CGPoint point = [touch locationInView:[touch view]];
	int i = (point.x - START_POS_X) / BTN_WIDTH;
	int j = (point.y - START_POS_Y) / BTN_HEIGHT;
	if(i >= 0 && j >= 0 && i < 3 && j < 3 ) {
		[delegate chooseValueForDealer:(i + j * 3)];
	}
	else if (j == 3 && i == 2) {
		[delegate chooseValueForDealer:9];
	} else {
		[delegate chooseValueForDealer:-1];
	}
}

- (void)dealloc {
    [super dealloc];
}


@end
